/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.micda.moroccoby.common.dao;

import com.micda.moroccoby.common.entities.Categorie;
import com.micda.moroccoby.common.entities.Produit;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Administrateur
 */

@Stateless
public class ProduitDAO extends GenericDAO<Produit, Integer> {

    @PersistenceContext(unitName = "MoroccoByPersistence")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ProduitDAO() {
        super(Produit.class);
    }

    public List<Produit> getProduitByCategorie(Integer idCateg) {
        Categorie categorie = new Categorie();
        categorie.setId(idCateg);
        Query q = em.createQuery("select P from " + Produit.class.getName() + " P where P.categorie = :categorie");
        return q.setParameter("categorie", categorie).getResultList();
    }
}
